FROM 172.20.7.86:5001/conda/miniconda-311

LABEL maintainer="Gaoyu <gaoyu.ssdut@icloud.com>"

# 设置环境变量
ENV PATH /root/miniconda3/bin:/root/miniconda3/condabin:$PATH
# 基础镜像中包含python3.11和常用包的conda环境
ENV CONDA_DEFAULT_ENV=dutwater11
ENV PATH /root/miniconda3/envs/myenv/bin:$PATH
RUN echo $PATH

# 安装系统依赖
RUN apt-get update && apt-get install -y \
    libgl1-mesa-glx \
    libglib2.0-0 \
    libsm6 \
    libxext6 \
    libxrender-dev \
    libgomp1 \
    && rm -rf /var/lib/apt/lists/*

# 工作目录
WORKDIR /app

# 设置时区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# 复制依赖文件
COPY requirements.txt /app/

# 安装 Python 依赖（使用阿里云镜像加速）
RUN pip install --no-cache-dir -r requirements.txt \
    -i https://mirrors.aliyun.com/pypi/simple/ \
    --trusted-host mirrors.aliyun.com

# 复制项目文件
COPY . /app/

# 创建必要的目录
RUN mkdir -p /app/storage/conversations \
    /app/storage/parameters \
    /app/storage/logs \
    /app/ssl

# 暴露端口
EXPOSE 8084

# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
    CMD curl -f http://localhost:8084/api/llm/health || exit 1

# 默认使用HTTP (端口8084)
# 如需HTTPS，启动容器时添加参数: --ssl
# 并挂载证书: -v /etc/letsencrypt:/etc/letsencrypt:ro
#
# HTTPS使用说明：
# 1. 运行HTTPS容器：
#    docker run --name hydromodel_llm -d --restart=unless-stopped \
#      -p 8084:8084 \
#      -v $(pwd)/storage:/app/storage \
#      -v /etc/letsencrypt:/etc/letsencrypt:ro \
#      -e USE_SSL=true \
#      -e SSL_CERTFILE=/etc/letsencrypt/live/ws.waterism.tech/fullchain.pem \
#      -e SSL_KEYFILE=/etc/letsencrypt/live/ws.waterism.tech/privkey.pem \
#      hydromodel_llm:latest
#
# 或使用快捷部署脚本:
#    chmod +x deploy.sh
#    ./deploy.sh
#
# 注意：
# - 使用 Let's Encrypt 正式证书（浏览器信任）
# - 前端API地址: https://ws.waterism.tech:8084
CMD ["python", "main.py"]

